#pragma once

#include "Common.h"
#include "Shader.h"



// Desired opengl version
#define OPENGL_MAJOR_VER	3
#define OPENGL_MINOR_VER	2

// Namespace
namespace davrenderer { 
	
	class Renderer; 

	// Default window parameters
	const string WINDOW_DEFAULT_TITLE = "DavEngine";
	enum {
		WINDOW_DEFAULT_WIDTH		= 800,
		WINDOW_DEFAULT_HEIGHT		= 600,
		WINDOW_DEFAULT_REDBITS		= 0,
		WINDOW_DEFAULT_GREENBITS	= 0,
		WINDOW_DEFAULT_BLUEBITS		= 0,
		WINDOW_DEFAULT_ALPHABITS	= 0,
		WINDOW_DEFAULT_DEPTHBITS	= 0,
		WINDOW_DEFAULT_STENCILBITS	= 0,
		WINDOW_DEFAULT_MODE			= GLFW_WINDOW,
		WINDOW_DEFAULT_POS_X		= 0,
		WINDOW_DEFAULT_POS_Y		= 0
	};

	// Shader id's
	enum {
		FLAT_SHADER,
		MAX_SHADER,

		DEFAULT_SHADER = FLAT_SHADER
	};

}
using namespace davrenderer;



/* * * * * * * * * *
 * Renderer
 * Author:	David Ogle
 * Date:	28/03/2012
 * Renderer object
 * * * * * * * * * */
class davrenderer::Renderer
{
private:

	Renderer(Renderer &r);	// Hide copy constructor

protected:

	bool init;
	uint width;
	uint height;

public:

	// Constructor
	Renderer(	uint width			= WINDOW_DEFAULT_WIDTH, 
				uint height			= WINDOW_DEFAULT_HEIGHT, 
				string title		= WINDOW_DEFAULT_TITLE,
				uint mode			= WINDOW_DEFAULT_MODE,
				uint redbits		= WINDOW_DEFAULT_REDBITS, 
				uint greenbits		= WINDOW_DEFAULT_GREENBITS, 
				uint bluebits		= WINDOW_DEFAULT_BLUEBITS, 
				uint alphabits		= WINDOW_DEFAULT_ALPHABITS, 
				uint depthbits		= WINDOW_DEFAULT_DEPTHBITS, 
				uint stencilbits	= WINDOW_DEFAULT_STENCILBITS
				);
	~Renderer(void);

	void initShaders();		// Initialize the shaders



	// Window properties
	bool	isInitialized() { return init; }
	uint	getHeight()		{ glfwGetWindowSize((int*)(&this->width), (int*)(&this->height)); return height; };
	uint	getWidth()		{ glfwGetWindowSize((int*)(&this->width), (int*)(&this->height)); return width; };



	// Renderer functions
	void	swapBuffers()	{ glfwSwapBuffers(); };







	// Debug info
	void printDebugInfo() {
		#ifdef _DEBUG
		if(glfwGetWindowParam(GLFW_OPENED)) {
			cout << "GLFW DEBUG INFORMATION" << endl;
			cout << "OpenGL version:\t" << glfwGetWindowParam(GLFW_OPENGL_VERSION_MAJOR) << "." << glfwGetWindowParam(GLFW_OPENGL_VERSION_MINOR) << endl;
			cout << "OpenGL profile:\t" << glfwGetWindowParam(GLFW_OPENGL_PROFILE) << endl;
			cout << "Forward compat:\t" << ((glfwGetWindowParam(GLFW_OPENGL_FORWARD_COMPAT) == 0) ? "No" : "Yes") << endl;
			cout << "Refresh Rate:\t"	<< glfwGetWindowParam(GLFW_REFRESH_RATE) << "Hz" << endl;
		} else {
			cout << "No GLFW window is open." << endl;
		}
		#endif
	};
	
};

